package cn.tedu.sp04.feign;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.web.util.JsonResult;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: LeeYu
 * @Date: 2020/11/26 10:50
 */
@Component
public class ItemClientFB implements ItemClient{
    @Override
    public JsonResult<List<Item>> getItems(String orderId) {
        //模拟有redis缓存数据，调用商品失败，从redis取出缓存发送给客户端
        if (Math.random()<0.5){
            List<Item> items= Arrays.asList(new Item[]{
               new Item(1,"商品1",1),
               new Item(2,"商品1",2),
               new Item(3,"商品1",3),
               new Item(4,"商品1",4),
               new Item(5,"商品1",5),
            });
            return JsonResult.ok().data(items);
        }
        return JsonResult.err().msg("获取商品列表失败！");
    }

    @Override
    public JsonResult<?> decreaseNumber(List<Item> items) {
        return JsonResult.err().msg("新增商品失败！");
    }
}
